package com.hhj.service.impl;

import com.hhj.dao.UserDao;
import com.hhj.pojo.User;
import com.hhj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    @Qualifier("userDao")
    private UserDao userDao;


    @Override
    public boolean add(User user) {
        int add = userDao.add(user);
        if (add>0){
            return true;
        }
        return false;
    }

    @Override
    public User login(String userCode, String userPassword) {
        User loginUser = userDao.getLoginUser(userCode);
        if (loginUser!=null){
            if (userPassword.equals(loginUser.getUserPassword())){
                return loginUser;
            }else {
                return null;
            }
        }
        return null;

    }

    @Override
    public List<User> getUserList(String queryUserName, int queryUserRole, int currentPageNo, int pageSize) {
        List<User> userList = userDao.getUserList(queryUserName, queryUserRole, currentPageNo, pageSize);
        return userList;
    }

    @Override
    public int getUserCount(String queryUserName, int queryUserRole) {
        int userCount = userDao.getUserCount(queryUserName, queryUserRole);
        return userCount;
    }

    @Override
    public User selectUserCodeExist(String userCode) {
        User loginUser = userDao.getLoginUser(userCode);
        return loginUser;
    }

    @Override
    public boolean deleteUserById(Integer delId) {
        int i = userDao.deleteUserById(delId);
        if (i!=0){
            return true;
        }
        return false;
    }

    @Override
    public User getUserById(String id) {

        return userDao.getUserById(id);
    }

    @Override
    public boolean modify(User user) {
        int modify = userDao.modify(user);
        if (modify!=0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updatePwd(int id, String pwd) {
        int i = userDao.updatePwd(id, pwd);
        if (i !=0){
            return true;
        }
        return false;
    }
}
